{extend name="public/base" /}
{block name="pjax_container"}
<?php
    $titleTypeName = '任务添加';
?>
<style>
    


    .content-header>.breadcrumb>li {
        color: #999;
    }

    .content-header>.breadcrumb>.active {
        color: #666;
    }

    .content-header {
        height: 51px;

    }

    .btn-primary {
        background-color: #1890FF;
        color: #fff;
        border: none;
        border-radius: 3px !important;
        margin-left: 15px;
        padding: 7px 13px;
    }

    .box-primary {
        border-top-color: #ecf0f5 !important;
        border-top-width: 16px;

    }

    .btn-primary:hover {
        background-color: #1890FF;
        color: #fff;
        border: none;
        opacity: .9;
        border-radius: 3px !important;
    }

    .delete-one {
        background-color: ff4141 !important;
        margin-left: 15px;
        border-radius: 6px;
    }

    .sreachs {
        background-color: #1890FF;
        color: #fff;
        border: none;
        border-radius: 6px !important;
        margin-left: 15px;
        padding: 7px 15px;
    }

    .nav-tabs-custom {
        margin-bottom: 20px;
        background: #fff;
        box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
        border-radius: 3px;
        margin-top: 16px;
    }

    tr>th,
    td {
        text-align: center;
    }

    label {
        margin-left: 10px;
        color: #504F73 !important;
    }

    .select2-container--default .select2-selection--single,
    .select2-selection .select2-selection--single {
        border: 1px solid #d2d6de;
        border-radius: 6px;
        padding: 6px 12px;
        height: 34px;
    }

    .tab-content {
        margin: 20px 0 40px;
        border-bottom: 0px solid #f3f3f3;
        padding-bottom: 40px;
    }

    .submits {
        border: none;
        outline: none;
        background-color: #1890FF;
        padding: 8px 20px;
    }

    input[name="apply_integral"] {
        width: 48% !important;
    }

    .modal-content {
        margin-top: 150px;
        width: 600px;
        height: 690px;

    }

    .modal-body {
        padding: 27px;
        width: 856px;
        height: 570px;
        display: flex;
    }

    .modal-right {
        flex: 1;
        border: 1px solid #eee;
        margin-left: 30px;
    }

    .modal-left {
        height: 100%;
    }

    .modal-right>h4 {
        width: 100%;
        display: flex;
        justify-content: space-around;
    }

    .form-control {
        border-radius: 6px;
    }

    .table-body {
        width: 540px;
        height: 462px;
        border-radius: 6px;
        background-color: #eee;
    }

    .table-left {
        margin-right: 2%;
        width: 49%;
        height: 100%;
        float: left;
        border: 1px solid #eee;
        background-color: #fff;
    }

    .table-right,
    .table-right2 {
        width: 49%;
        height: 100%;
        border: 1px solid #eee;
        float: left;
        padding-top: 10px;
        background-color: #fff;
    }

    .layui-tree-entry {
        height: 100%;
        width: 100%;
        padding-right: 10px;
        line-height: 24px;

    }

    .table-right>p,
    .table-right2>p {
        text-align: center;
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
        font-size: 14px;
    }

    .table-right>h4,
    .table-right2>h4 {
        text-align: center;
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
        font-size: 14px;

    }

    .table-right>p>span,
    .table-right2>p>span {
        text-align: center;
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
        font-size: 14px;
        width: 80%;
        display: inline-block;
        letter-spacing: 1px;

    }

    input[type=checkbox],
    input[type=radio] {
        margin-top: 11px;
    }

    .modal-right h4 {
        width: 100%;
        font-size: 14px;
        text-align: center;
    }

    .move {
        width: 524px;
        height: 283px;
    }


    .magic-radio,
    .magic-checkbox {
        position: absolute;
        display: none;

    }

    .magic-radio+label,
    .magic-checkbox+label {
        position: relative;
        display: flex;
        align-items: center;
        padding-left: 0;
        cursor: pointer;
    }

    .magic-radio+label:before,
    .magic-checkbox+label:before {
        display: inline-block;
        width: 20px;
        height: 20px;
        content: '';
        border: 1px solid #c0c0c0;
        margin-right: 5px;
    }

    .magic-checkbox+label:before {
        top: -5px;
    }

    .magic-radio+label:after,
    .magic-checkbox+label:after {
        position: absolute;
        display: none;
        content: '';
        margin-top: 5px;
    }



    .magic-radio:checked+label:after,
    .magic-checkbox:checked+label:after {
        display: block;
    }

    .magic-radio+label:before {
        border-radius: 50%;
    }

    .magic-radio+label:after {
        top: 10px;
        left: 6px;
        width: 8px;
        height: 8px;
        border-radius: 50%;
        background: #3e97eb;
    }

    .magic-radio:checked+label:before {
        border: 1px solid #3e97eb;
    }

    .magic-radio:checked[disabled]+label:before {
        border: 1px solid #c9e2f9;
    }

    .magic-checkbox+label:before {
        border-radius: 3px;
    }

    .magic-checkbox+label:after {
        top: 2px;
        left: 7px;
        box-sizing: border-box;
        width: 6px;
        height: 12px;
        transform: rotate(45deg);
        border-width: 2px;
        border-style: solid;
        border-color: #fff;
        border-top: 0;
        border-left: 0;
    }

    .magic-checkbox+label:after {
        top: -2px;
    }

    .magic-checkbox:checked+label:before {
        border: #1890FF;
        background: #1890FF;
    }

    .magic-checkbox:checked[disabled]+label:before {
        border: #1890FF;
        background: #1890FF;
    }


    #myModal10 .modal-content {
        margin-top: 150px;
        width: 900px;
        height: 700px;
    }
</style>
<section class="content-header">
    <ol class="breadcrumb">
        <li>任务大厅</li>
        <li>任务发布</li>
        <li class="active">{$titleTypeName}</li>
    </ol>
</section>
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <form class="form-horizontal" method="POST"
                action="/{$Think.MODULE_NAME}/{$Think.CONTROLLER_NAME}/issue_store"  onsubmit="return false">
                <input name="check_opinion" id="check_opinion" type="hidden" value="">
                <input name="id" type="hidden" value="{$info.id??''}">
                <div class="nav-tabs-custom">
                    <ul class="nav nav-tabs">
                        <li class="pull-right"><a href="javascript:history.back(-1)" class="btn btn-sm"
                                style="padding:10px 2px;"><i class="fa fa-list"></i> 返回</a></li>
                    </ul>
                    <div class="tab-content">
                        <div class="tab-pane active" id="tab1">
                            {include file="form/input" title="任务名称" name="name"/}
                            {include file="form/input_textarea" title="任务内容" name="content"/}
                            <div class="form-group">
                                <label class="col-sm-2 control-label ">任务类型:</label>
                                <div class="col-sm-5 radio" style="line-height: 37px; display: flex;padding-top: 0;">
                                    <input class="minimal magic-radio" type="radio" id="is_lottery_ticket1" name="type"
                                        value="1" {if condition="isset($info['type'])&&$info['type'] != 1" }{else}checked{/if} />
                                    <label for="is_lottery_ticket1">指定任务</label>
                                    <input class="minimal magic-radio" type="radio" id="is_lottery_ticket2" name="type"
                                        value="2" {if condition="isset($info['type'])&&$info['type'] == 2" } checked {/if} />
                                    <label for="is_lottery_ticket2">悬赏任务</label>
                                </div>
                            </div>

                            <div class="check" {if condition="isset($info['type']) && $info.type == 2" }{else}style="display: none" {/if}> <div class="form-group">
                                <label class="col-sm-2 control-label">报名奖分:</label>
                                <div class="col-sm-2">
                                    <input name="apply_integral" style="border-radius: 6px;"
                                        class="form-control classname" value="{$info.apply_integral??''}"
                                        placeholder="报名奖分" />
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">报名截止:</label>
                                <div class="col-sm-2">
                                    <input name="apply_end_time" style="border-radius: 6px;"
                                        class="form-control classname apply_end_time"
                                        value="{$info.apply_end_time?date('Y-m-d H:i:s',$info.apply_end_time):''}"
                                        placeholder="报名截止时间" />
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">消息推送范围:</label>
                                <div class="col-sm-2" style="display: flex;">
                                    <div class="add_message_push"
                                        style="height: 100%;min-width: 120px;;line-height: 35px;border: 1px solid #d2d6de;border-radius: 5px;padding: 0 10px;color: #848684;cursor: pointer;">
                                        添加消息推送人</div>
                                        <!-- 编辑时循环添加ipnut框 value为id  -->
                                    {if condition="isset($info['xs'])"}
                                    {foreach name="$info['xs']" item="vo"}
                                        <input type="hidden" name="push[]" user_name="{$take_list[$vo['user_id']]['name']}" value="$vo['user_id']" input_user_num="{$take_list[$vo['user_id']]['job_number']}" apart_name="{$take_list[$vo['user_id']]['d_name']}" limits_b="{$take_list[$vo['user_id']]['integral_b']}">
                                    {/foreach}
                                    {/if}
                                    <span
                                        style="width: 40%; height: 100%;line-height: 35px;letter-spacing: 1px; white-space: nowrap;margin-left: 10px;color: #848684;">已选择<b>{$info.xs?count($info.xs):'0'}</b>人</span>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">任务负责人:</label>
                            <div class="col-sm-2">
                                <input name="principal_user_name" style="border-radius: 6px;"
                                    class="form-control classname"
                                    value="{:isset($info['principal_user_id']) ? $users[$info['principal_user_id']]['name']??'' : ''}"
                                    placeholder="任务负责人" />
                                <input type="hidden" name="principal_user_id" value="{$info.principal_user_id??''}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label" for="">截止日期:</label>
                            <div class="col-sm-2">
                                <input class="form-control timepicker" name="end_time" {if
                                    condition="isset($info['end_time'])"
                                    }value="{:date('Y-m-d H:i:s',$info['end_time'])}" {/if} placeholder="截止日期"
                                    style="border: 1px solid #ccc;height: 34px;border-radius: 6px;" autocomplete="off">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">延期汇报扣分(分/天):</label>
                            <div class="col-sm-2">
                                <input style="border-radius: 6px;" class="form-control" name="del_integral"
                                    value="{$info['del_integral']|default=''}" placeholder="延期汇报扣分(分/天)" {if
                                    condition="substr('del_integral',0,8)=='password'" } autocomplete="off" {/if}>
                            </div>
                            <div class="col-sm-2" style="line-height: 34px;font-size: 16px;">
                                <input type="checkbox" name="" class="minimal del_type_name"/> 是否翻倍扣分
                                <input type="hidden" name="del_type" value="1">
                            </div>
                        </div>
                        <div class="form-group del_type_ture" style="display:none;">
                            <label class="col-sm-2 control-label">扣分上限:</label>
                            <div class="col-sm-2">
                                <input style="border-radius: 6px;" name="double_max" value="{$info.double_max??''}"
                                    class="form-control" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">任务参与人</label>
                            <div class="col-sm-2" style="display: flex;">
                                <div class="add_take"
                                    style="height: 100%;line-height: 35px;border: 1px solid #d2d6de;border-radius: 5px;padding: 0 10px;color: #848684;cursor: pointer;">
                                    添加参与人</div>
                                <!-- 编辑时循环添加ipnut框 value为id  -->
                                {if condition="isset($info['cy'])"}
                                {foreach name="$info['cy']" item="vo" key="ko"}
                                <input type="hidden" name="take[]" user_name="{$take_list[$vo['user_id']]['name']}" value="{$vo['user_id']}" input_user_num="{$take_list[$vo['user_id']]['job_number']}" apart_name="{$take_list[$vo['user_id']]['d_name']}" limits_b="{$take_list[$vo['user_id']]['integral_b']}">
                                {/foreach}
                                {/if}
                                <span
                                    style="width: 40%; height: 100%;line-height: 35px;letter-spacing: 1px; white-space: nowrap;margin-left: 10px;color: #848684;">
                                    已选择<b>{$info.cy?count($info.cy):'0'}</b>人
                                </span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">初审人:</label>
                            <div class="col-sm-2">
                                <input name="first_check_user_name" style="border-radius: 6px;"
                                    class="form-control classname"
                                    value="{if condition="isset($info.first_check_user_id)"} {$users[$info.first_check_user_id]['name']??''} {else} {$check_user_data.first_name??''} {/if} "
                                    placeholder="初审人" autocomplete="off"/>
                                <input type="hidden" name="first_check_user_id" value="{if condition="isset($info.first_check_user_id)"} {$info.first_check_user_id??''} {else} {$check_user_data.first_check_user_id??''} {/if}">
                            </div>

                            <label class="col-sm-1 control-label">终审人:</label>
                            <div class="col-sm-2">
                                <input name="last_check_user_name" style="border-radius: 6px;"
                                    class="form-control classname"
                                    value="{if condition="isset($info.last_check_user_id)"} {$users[$info.last_check_user_id]['name']??''} {else} {$check_user_data.last_name??''} {/if} "
                                    placeholder="请选择人员" limits_b="" autocomplete="off"/>
                                <input type="hidden" name="last_check_user_id" value="{if condition="isset($info.last_check_user_id)"} {$info.last_check_user_id??''} {else} {$check_user_data.last_check_user_id??''} {/if}">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="box-footer">
                    <div class="col-sm-2"></div>
                    <div class="col-sm-4">
                        <div class="btn-group pull-right">
                            <button type="submit" id="main_submit"  data="{$user_id}" class="btn btn-info pull-right"
                                data-loading-text="&lt;i class='fa fa-spinner fa-spin '&gt;&lt;/i&gt; 提交">提交</button>
                            <button class="submits" style="display: none"></button>
                        </div>
                    </div>
                </div>

        </div>
        </form>
    </div>
    </div>
</section>
<!-- 监听悬赏任务单选框 -->
<script>
    //监听悬赏任务单选框
    $("input:radio[name='type']").click(function (e) {
        var val = $("input:radio[name='type']:checked").val();
        if (val == 2) {
            $(".tab-content .check").show();
        } else {
            $(".tab-content .check").hide();
            //重置悬赏任务填写项
            $(".tab-content .check input[name='apply_end_time']").val("");
            $(".tab-content .check input[name='apply_integral']").val("");
            $(".tab-content .check input[name='push[]']").remove();
            $(".tab-content .add_message_push").siblings("span").find("b").html(0);
        }
        // console.log(val);
    });
    //监听扣分上限
    $("input[name='del_integral']").change(function(){
        var score = $("input[name='last_check_user_name']").attr("limits_b");//终审人的分值权限
        var now_score = $(this).val();
        var is_out = score - now_score;
        if( is_out < 0){
            $("input[name='last_check_user_name']").val("").attr("limits_b","");
            $("input[name='last_check_user_id']").val("");
        }
    });
    // 时间选择器
    layui.use(['tree', 'laydate'], function () {
        var tree = layui.tree;
        var laydate = layui.laydate;
        var end_time  = laydate.render({
            elem: '.timepicker'
            ,min: 0 //0天前
            // , max: 7 //7天后
            ,type: "datetime"//样式
        });
        var apply_end_time  = laydate.render({
            elem: '.apply_end_time'
            , min: 0 //0天前
            // , max: 7 //7天后
            , type: 'datetime' //样式
        });
    });
    //监听是否翻倍扣分
    $(function(){
        $('input[type="checkbox"].minimal').iCheck({
            checkboxClass: 'icheckbox_minimal-blue',
        });
         $(".del_type_name").on("ifClicked",function(e){
            if (e.target.checked) {
                console.log(0);
                $(".del_type_ture").hide();
                $(".del_type_ture input").val("");
                $("input[name='del_type']").val(1);
            } else {
                console.log(1);
                $(".del_type_ture").show();
                $("input[name='del_type']").val(2);
            }
        })
    })
    // $(".del_type_name").on("ifChecked", function(e){
    //         alert(e.type + 'callback');
    //         if (e.target.checked) {
    //             // _checkbox.iCheck("uncheck");
    //             $(".del_type_ture").hide();
    //             $(".del_type_ture input").val("");
    //             console.log(0);
    //         }else {
    //             // _checkbox.iCheck("check");
    //             console.log(1);
    //             $(".del_type_ture").show();
    //         }
    //     });
</script>
<!-- Modal 弹出层重写 单选  -->
<link rel="stylesheet" href="__STATIC__/global/an_tree_css/an_tree_css.css">
<div class="modal fade" id="myModal_single" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">人员选择</h4>
            </div>
            <div class="modal-body">
                <div class="modal-left">
                    <div class="modal-left-title" style="margin-bottom: 20px;">
                        <div class="input-group">
                            <input name="search_user_name" type="text" class="form-control" placeholder="">
                            <span class="input-group-btn">
                                <button class="btn btn-info search_btn" type="button"
                                    style="width: 47px; height: 34px; background-color: #1890FF;border: none;outline: none;">
                                    <span class="glyphicon glyphicon-search"></span>
                                </button>
                            </span>
                        </div>
                    </div>
                    <div class="input-group table-body">
                        <div class="table-left">
                            <div class="an_tree">

                            </div>
                        </div>
                        <div class="table-right">
                            <div class="an_tree_list">
                                <div class="an_list_title">

                                </div>
                                <div class="an_list_con">
                                    <!-- <div class="an_list_item">
                                        <div class="item_info">
                                            <span class="name">aaa</span>/
                                            <span>88</span>/
                                            <span>部门</span>
                                        </div>
                                        <div class="item_box item_box_check"><i class="fa fa-check"></i></div>
                                    </div> -->
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary popups_submit">确认</button>
            </div>
        </div>
    </div>

</div>
<!-- 单选弹窗操作  -->
<script>
    var double_max;//扣分上限
    var first_id="";//初审人id
    var last_id="";//终审人id
    var principal_user_id="";//任务负责人id
    var pcqt_people = [];//排除其他人员数组
    var now_item_name;//名字输入框
    var now_item_id;//id输入框
    var user_type;
    //确认按钮
    $('#myModal_single .popups_submit').click(function (e) {
        $('#myModal_single').modal('hide');
        var checked = $(".an_tree_list").find(".list_item_check");
        now_item_name.val(checked.attr("user_name"));
        now_item_id.val(checked.attr("user_id"));
        now_item_name.attr("limits_b",checked.attr("limits_b"))
    });
    //当弹窗关闭时执行重置弹窗
    $('#myModal_single').on('hidden.bs.modal', function () {
        // 执行一些动作...重置弹窗
        $(".an_tree_list .an_list_title").html("");
        $(".an_tree_list .an_list_con").html("");
        $(".tree_txt_active").removeClass("tree_txt_active");
        $(".an_tree_pack").hide();
        $(".an_tree .fa").removeClass("fa-caret-down").addClass("fa-caret-right");
        $("#myModal_single input[name='search_user_name']").val("");
    });
    // 任务负责人
    $("input[name='principal_user_name']").focus(function () {
        $('#myModal_single').modal('show');
        double_max = 0;
        now_item_name = $(this);
        now_item_id = $("input[name='principal_user_id']");//节点
        last_id = $("input[name='last_check_user_id']").val();//id值
        pcqt_people = hqcyr_array();//获取参与人数组
        pcqt_people = pcqt_people.concat(hqtsr_array());
        pcqt_people.push(last_id,principal_user_id);//添加终审人,初审人
        user_type = 0;
    });
    // 初审人
    $("input[name='first_check_user_name']").focus(function () {
        $('#myModal_single').modal('show');
        double_max = $("input[name='del_integral]").val();
        now_item_name = $(this);//节点
        now_item_id = $("input[name='first_check_user_id']");//节点
        last_id = $("input[name='last_check_user_id']").val();//id值
        pcqt_people=[];
        pcqt_people.push(last_id);
        user_type = 1;
    });
    // 终审人
    $("input[name='last_check_user_name']").focus(function () {
        $('#myModal_single').modal('show');
        double_max = $("input[name='del_integral']").val();
        now_item_name = $(this);//节点
        now_item_id = $("input[name='last_check_user_id']");//节点
        first_id = $("input[name='first_check_user_id']").val();//id值
        principal_user_id = $("input[name='principal_user_id']").val();//id值
        pcqt_people = hqcyr_array();//获取参与人数组
        pcqt_people = pcqt_people.concat(hqtsr_array());
        pcqt_people.push(first_id,principal_user_id);//添加终审人,初审人
        user_type = 2;
    });
    function hqcyr_array(){
        var now_item_ids = [];
        for (let i = 0; i < $(".add_take").siblings("input[name='take[]']").length; i++) {
            now_item_ids.push($(".add_take").siblings("input[name='take[]']").eq(i).val());
        }
        return now_item_ids;
    }
    function hqtsr_array(){
        var now_item_ids = [];
        for (let i = 0; i < $(".add_message_push").siblings("input[name='push[]']").length; i++) {
            now_item_ids.push($(".add_message_push").siblings("input[name='push[]']").eq(i).val());
        }
        return now_item_ids;
    }
</script>
<!-- 树结构js操作 单选  -->
<script>
    $("#myModal_single .an_tree").on("click", ".fa", function () {
        $(this).toggleClass("fa-caret-down");
        $(this).toggleClass("fa-caret-right");
        $(this).parents(".an_tree_set").eq(0).children(".an_tree_pack").toggle();
    });
    $("#myModal_single").on("click", ".an_tree_txt,.search_btn", function () {
        $(".an_tree").find(".tree_txt_active").removeClass("tree_txt_active");
        $(this).addClass("tree_txt_active");
        var department_id = $(this).attr("data_id");
        var department_name = $(this).html();
        var user_name = $("#myModal_single input[name='search_user_name']").val();
        // console.log(user_name);
        $.ajax({
            type: 'get',
            url: "{:url('base/base_department_per')}",
            data: {'department_id' : department_id,'score' : double_max,'first_check_user_id' : pcqt_people,'last_check_user_id' : pcqt_people,'user_type' : user_type ,'user_name' : user_name},
            dataType:"json",
            success: function (data) {
                // var json = JSON.parse(data);
                // console.log(data);
                var content = '';
                $.each(data, function (index, value) {
                    if(value.limits==undefined){
                         var limits=0;
                    }else{
                        var limits=value.limits.b;
                    }
                    content += '<div class="an_list_item" user_name="'+value.name+'" user_id="'+value.id+'" limits_b="'+limits+'"><div class="item_info"><span class="name">' + value.name + '</span>/<span>' + value.job_number + '</span>/<span>' + value.department_name + '</span></div><div class="item_box "><i class="fa fa-check"></i></div></div>'
                });
                $('.an_list_con').html("");
                $('.an_list_con').append(content);
                $('.an_list_title').html(department_name + data.length + '人');
            }
        })
    });
    $("#myModal_single .an_tree_list").on("click", ".an_list_item", function () {
        $(this).siblings().removeClass("list_item_check");
        $(this).toggleClass("list_item_check")
    })
</script>
<!-- 递归填充目录 单选  -->
<script>
    var an_tree = ergodic({$department});
    $("#myModal_single .an_tree").append(an_tree);
    function ergodic(data) {
        var content = '';
        $.each(data, function (index, value) {
            if (value.children != "") {
                var children = ergodic(value.children);
                content += '<div class="an_tree_set"><div class="an_tree_entry"><div class="an_tree_main"><span class="an_tree_icon"><i class="fa fa-caret-right"></i></span><span class="an_tree_txt" data_id="' + value.id + '" data_pid="' + value.pid + '">' + value.title + '</span></div></div><div class="an_tree_pack">' + children + '</div></div>';
            } else {
                content += '<div class="an_tree_set"><div class="an_tree_entry"><div class="an_tree_main"><span class="an_tree_icon"></span><span class="an_tree_txt" data_id="' + value.id + '" data_pid="' + value.pid + '">' + value.title + '</span></div></div><div class="an_tree_pack"></div></div>';
            }
        });
        return content;
    }
</script>


<!-- Modal 弹出层重写 多选   -->
<div class="modal fade" id="myModal_multiple" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="myModalLabel10">人员选择</h4>
            </div>
            <div class="modal-body">
                <div class="modal-left">
                    <div class="modal-left-title" style="margin-bottom: 20px;">
                        <div class="input-group">
                            <input type="text" name="search_user_name" class="form-control" placeholder="">
                            <span class="input-group-btn">
                                <button class="btn btn-info search_btn" type="button"
                                    style="width: 47px; height: 34px; background-color: #1890FF;border: none;outline: none;"><span
                                        class="glyphicon glyphicon-search"></span></button>
                            </span>
                        </div>
                    </div>
                    <div class="input-group table-body">
                        <div class="table-left">
                            <div class="an_tree">

                            </div>
                        </div>
                        <div class="table-right">
                            <div class="an_tree_list">
                                <div class="an_list_title">

                                </div>
                                <div class="an_list_con">
                                    <!-- <div class="an_list_item">
                                        <div class="item_info">
                                            <span class="name">aaa</span>/
                                            <span>88</span>/
                                            <span>部门</span>
                                        </div>
                                        <div class="item_box item_box_check"><i class="fa fa-check"></i></div>
                                    </div> -->
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-right">
                    <div class="multiresult_header">
                        <div>已选择<span class="number">0</span>个</div>
                        <div class="header_clear">清空</div>
                    </div>
                    <div class="multiresult_list">
                        <!-- <div class="an_list_item">
                            <div class="item_info">
                                <span class="name">aaa</span>/
                                <span>88</span>/
                                <span>部门</span>
                            </div>
                            <div class="item_box item_box_check"><i class="fa fa-check"></i></div>
                        </div> -->
                        
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary popups_submit" id="submit2">确认</button>
            </div>
        </div>
    </div>
</div>
<!-- 多选弹窗操作  -->
<script>
    var now_item_multiple="";//名字输入框
    var input_name="";
    $(".add_take").click(function(){
        $('#myModal_multiple').modal('show');
        now_item_multiple=$(this);
        input_name = "take[]";
        new_right_add();
        principal_user_id = $("input[name='principal_user_id']").val();//id值
        last_id = $("input[name='last_check_user_id']").val();//id值
        pcqt_people = hqtsr_array();
        pcqt_people.push(principal_user_id,last_id);//添加终审人,添加抄送人
    });
    $(".add_message_push").click(function(){
        $('#myModal_multiple').modal('show');
        now_item_multiple=$(this);
        input_name = "push[]";
        new_right_add();
        principal_user_id = $("input[name='principal_user_id']").val();//id值
        last_id = $("input[name='last_check_user_id']").val();//id值
        pcqt_people = hqcyr_array();
        pcqt_people.push(principal_user_id,last_id);//添加终审人,添加抄送人
    });
     //确认按钮
    $('#myModal_multiple .popups_submit').click(function (e) {
        $('#myModal_multiple').modal('hide');
        var check_all = $("#myModal_multiple .multiresult_list .an_list_item");
        var content="";
        for (let i = 0; i < check_all.length; i++) {
            var input_value = check_all.eq(i).attr("user_id");
            var input_limits_b = check_all.eq(i).attr("limits_b");
            var input_user_name = check_all.eq(i).attr("user_name");
            var input_user_num = check_all.eq(i).find(".item_info span").eq(1).html();
            var input_apart_name = check_all.eq(i).find(".item_info span").eq(2).html();
            content += '<input type="hidden" name="'+input_name+'" user_name="'+input_user_name+'" value="'+input_value+'" user_name="'+input_user_name+'" input_user_num="'+input_user_num+'" apart_name="'+input_apart_name+'" limits_b="'+input_limits_b+'">';
        }
        now_item_multiple.siblings("input").remove();
        now_item_multiple.after(content);
        now_item_multiple.siblings("span").find("b").html(check_all.length);
        // var checked = $(".an_tree_list").find(".list_item_check");
        // now_item_name.val(checked.attr("user_name"));
        // now_item_id.val(checked.attr("user_id"));
        // now_item_name.attr("limits_b",checked.attr("limits_b"))
    });
    //当弹窗关闭时执行重置弹窗
    $('#myModal_multiple').on('hidden.bs.modal', function () {
        //执行一些动作...重置弹窗
        $(".an_tree_list .an_list_title").html("");
        $(".an_tree_list .an_list_con").html("");
        $(".tree_txt_active").removeClass("tree_txt_active");
        $(".an_tree_pack").hide();
        $(".an_tree .fa").removeClass("fa-caret-down").addClass("fa-caret-right");
        $("#myModal_multiple input[name='search_user_name']").val("");
        $("#myModal_multiple .header_clear").click();
    });
    //已选择，再进行补充选择时添加右侧选中
    function new_right_add(){
        var input = now_item_multiple.siblings("input");
        var content = ""
        for (let i = 0; i < input.length; i++) {
            input.eq(i).attr("");
            content += '<div class="an_list_item " user_name="'+input.eq(i).attr("user_name")+'" user_id="'+input.eq(i).attr("value")+'" limits_b="'+input.eq(i).attr("limits_b")+'"><div class="item_info"><span class="name">'+input.eq(i).attr("user_name")+'</span>/<span>'+input.eq(i).attr("input_user_num")+'</span>/<span>'+input.eq(i).attr("apart_name")+'</span></div><div class="item_box "><i class="fa fa-remove"></i></div></div>'
        }
        $("#myModal_multiple .multiresult_list").append(content);
    }
</script>
<!-- 树结构js操作 多选  -->
<script>
    $("#myModal_multiple .an_tree").on("click", ".fa", function () {
        $(this).toggleClass("fa-caret-down");
        $(this).toggleClass("fa-caret-right");
        $(this).parents(".an_tree_set").eq(0).children(".an_tree_pack").toggle();
    });
    //添加中间人员列表
    $("#myModal_multiple").on("click", ".an_tree_txt,.search_btn", function () {
        $(".an_tree").find(".tree_txt_active").removeClass("tree_txt_active");
        $(this).addClass("tree_txt_active");
        var department_id = $(this).attr("data_id");
        var department_name = $(this).html();
        var user_name = $("#myModal_multiple input[name='search_user_name']").val();
        // console.log(user_name);
        $.ajax({
            type: 'get',
            url: "{:url('base/base_department_per')}",
            data: {'department_id' : department_id,'user_name' : user_name,'user_type': 0,'last_check_user_id': pcqt_people,},
            dataType:"json",
            success: function (data) {
                // var json = JSON.parse(data);
                // console.log(data);
                var content = '';
                $.each(data, function (index, value) {
                    if(value.limits==undefined){
                         var limits=0;
                    }else{
                        var limits=value.limits.b;
                    }
                    content += '<div class="an_list_item" user_name="'+value.name+'" user_id="'+value.id+'" limits_b="'+limits+'"><div class="item_info"><span class="name">' + value.name + '</span>/<span>' + value.job_number + '</span>/<span>' + value.department_name + '</span></div><div class="item_box "><i class="fa fa-check"></i></div></div>'
                });
                $('#myModal_multiple .an_list_con').html("");
                $('#myModal_multiple .an_list_con').append(content);
                $('#myModal_multiple .an_list_title').html('<div>'+department_name + data.length + '人</div><div class="all_item_box"><i class="fa fa-check"></i></div>');
                left_add_active();
                check_all();
            }
        })
    });
    // 选中事件
    $("#myModal_multiple .an_tree_list").on("click", ".an_list_item", function () {
        $(this).toggleClass("list_item_check");
        var ischeck = $(this).attr("class");
        if (ischeck.indexOf("list_item_check") >= 0) {
            add_check();
        } else {
            del_check($(this).attr("user_id"));
        }
        check_all();
    });
    //全选按钮
    $("#myModal_multiple .an_tree_list").on("click", ".all_item_box", function () {
        $(this).toggleClass("all_item_box_check");
        var ischeck = $(this).attr("class");
        var all_item = $("#myModal_multiple .an_tree_list .an_list_item");
        if (ischeck.indexOf("all_item_box_check") >= 0) {
            all_item.addClass("list_item_check");
            add_check();
        } else {
            all_item.removeClass("list_item_check")
            for (let i = 0; i < all_item.length; i++) {
                del_check(all_item.eq(i).attr("user_id"));
            }
        }
        check_all();
    });
    //右侧删除事件
    $("#myModal_multiple .multiresult_list").on("click", ".item_box", function () {
        var user_id = $(this).parents(".an_list_item ").attr("user_id");
        del_check(user_id);
        check_all();
    });
    //右侧清空监听
    $("#myModal_multiple .multiresult_header").on("click", ".header_clear", function () {
        var all_item = $("#myModal_multiple .multiresult_list .an_list_item");
        for (let i = 0; i < all_item.length; i++) {
            del_check(all_item.eq(i).attr("user_id"));
        }
        check_all();
    });
    //全选按钮检测
    function check_all(){
        var all_item_num = $("#myModal_multiple .an_tree_list .an_list_item").length;
        var checked_item_num = $("#myModal_multiple .an_tree_list .list_item_check").length;
        if(all_item_num != 0 && all_item_num == checked_item_num){
            $("#myModal_multiple .an_tree_list .all_item_box").addClass("all_item_box_check");
        }else{
            $("#myModal_multiple .an_tree_list .all_item_box").removeClass("all_item_box_check");
        };
        //右侧选中人数统计
        var people_num = $("#myModal_multiple .multiresult_list .an_list_item").length;
        $("#myModal_multiple .multiresult_header .number").html(people_num);
    };
    //添加右侧选中项
    function add_check(){
        var item_ids = [];
        var all_checked_item = $("#myModal_multiple .an_list_con").find(".list_item_check");
        var now_checker_item = $("#myModal_multiple .multiresult_list .an_list_item");
        for (let i = 0; i < now_checker_item.length; i++) {
            item_ids.push(now_checker_item.eq(i).attr("user_id"));
        }
        for (let i = 0; i < all_checked_item.length; i++) {
            var now_id = all_checked_item.eq(i).attr("user_id");
            if ( $.inArray(now_id,item_ids) < 0 ) {
                var new_item = all_checked_item.eq(i).prop("outerHTML");
                new_item = new_item.replace("fa-check","fa-remove");
                new_item = new_item.replace("list_item_check","");
                $("#myModal_multiple .multiresult_list").append(new_item);
            } 
        }
        // console.log(item_ids);
    }
    //左侧第一次生成时检测是否有选中项
    function left_add_active(){
        var left_item_ids = [];
        var left_checked_item = $("#myModal_multiple .an_list_con .an_list_item");
        var right_checker_item = $("#myModal_multiple .multiresult_list .an_list_item");
        for (let i = 0; i < left_checked_item.length; i++) {
            left_item_ids.push(left_checked_item.eq(i).attr("user_id"));
        }
        for (let i = 0; i < right_checker_item.length; i++) {
            var user_id = right_checker_item.eq(i).attr("user_id");
            if ( $.inArray(user_id,left_item_ids) >= 0 ) {
                $("#myModal_multiple .an_list_con .an_list_item[user_id="+user_id+"]").addClass("list_item_check");
            }
        }  
    }
    //取消选中项
    function del_check(user_id){
        var left_item_ids = [];
        var right_item_ids = [];
        var left_checked_item = $("#myModal_multiple .an_list_con .an_list_item");
        var right_checker_item = $("#myModal_multiple .multiresult_list .an_list_item");
        for (let i = 0; i < left_checked_item.length; i++) {
            left_item_ids.push(left_checked_item.eq(i).attr("user_id"));
        }
        for (let i = 0; i < right_checker_item.length; i++) {
            right_item_ids.push(right_checker_item.eq(i).attr("user_id"));
        }
        if ( $.inArray(user_id,left_item_ids) >= 0 ) {
           $("#myModal_multiple .an_list_con .an_list_item[user_id="+user_id+"]").removeClass("list_item_check");
        }
        if ( $.inArray(user_id,right_item_ids) >= 0 ) {
            $("#myModal_multiple .multiresult_list .an_list_item[user_id="+user_id+"]").remove();
        }
    }
</script>
<!-- 递归填充目录 多选  -->
<script>
    var an_tree = ergodic({$department});
    $("#myModal_multiple .an_tree").append(an_tree);
    function ergodic(data) {
        var content = '';
        $.each(data, function (index, value) {
            if (value.children != "") {
                var children = ergodic(value.children);
                content += '<div class="an_tree_set"><div class="an_tree_entry"><div class="an_tree_main"><span class="an_tree_icon"><i class="fa fa-caret-right"></i></span><span class="an_tree_txt" data_id="' + value.id + '" data_pid="' + value.pid + '">' + value.title + '</span></div></div><div class="an_tree_pack">' + children + '</div></div>';
            } else {
                content += '<div class="an_tree_set"><div class="an_tree_entry"><div class="an_tree_main"><span class="an_tree_icon"></span><span class="an_tree_txt" data_id="' + value.id + '" data_pid="' + value.pid + '">' + value.title + '</span></div></div><div class="an_tree_pack"></div></div>';
            }
        });
        return content;
    }
</script>

<!-- 拟稿提交按钮触发弹窗DOM结构_ -->
<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel2">
    <div class="modal-dialog" role="document">
        <div class="modal-content move">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel2">提示</h4>
            </div>
            <div class="modal_body" style="width: 100%;padding: 20px;">
                <label style="width: 100%;margin: 0;">
                    请填写您的初审意见：
                    <textarea name="check_opinion_textarea" id="check_opinion_textarea" cols="45" rows="5"
                        style="display: block;width: 100%;max-height: 100px; margin:0;padding: 10px;border-radius: 5px;"
                        placeholder="可以输入一千字"></textarea>
                </label>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" id="tips_submit">确认</button>
            </div>
        </div>
    </div>
</div>
<!-- 点击提交，弹出提示框_ -->
<script>
    $("#main_submit").click(function () {
        var check_id = $("input[name='first_check_user_id']").val();
        var now_id = $(this).attr("data");
        if ( check_id == now_id ) {
            $('#myModal2').modal('show');
        }else{
             $(".submits").click();
        }
        return false;
    });
    $("#tips_submit").click(function (e) {
        var check_opinion = $("#check_opinion_textarea").val();
        $("#check_opinion").val(check_opinion);
        $('#myModal2').modal('hide');
        $(".submits").click();
    });
</script>

{/block}